package 天梯赛.tts44.moni.A9;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        int smax = Integer.parseInt(st.nextToken());

        List<Deque<Character>> list = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            String str = br.readLine();
            Deque<Character> deque = new LinkedList<>();
            for (int j = 0; j < str.length(); j++) {
                deque.addLast(str.charAt(j));
            }
            list.add(deque);
        }

        StringBuilder sb = new StringBuilder();
        Deque<Character> stack = new ArrayDeque<>();

        while (true) {
            String line = br.readLine();
            if (line == null) break;
            st = new StringTokenizer(line);
            while (st.hasMoreTokens()) {
                int x = Integer.parseInt(st.nextToken());
                if (x == -1) {
                    System.out.println(sb.toString());
                    return;
                }
                if (x != 0) {
                    Deque<Character> deque = list.get(x - 1);
                    if (!deque.isEmpty()) {
                        char res = deque.removeFirst();
                        if (stack.size() < smax) {
                            stack.push(res);
                        } else {
                            sb.append(stack.pop());
                            stack.push(res);
                        }
                    }
                } else {
                    if (!stack.isEmpty()) {
                        sb.append(stack.pop());
                    }
                }
            }
        }
    }
}
